package com.baiyun.util;

import java.util.ArrayList;
import java.util.Random;

public class CodeUtil {
    private CodeUtil(){}

    public static String getCode(){
        //创建litter用于储存大小写字母
        ArrayList<Character> litter = new ArrayList<>();
        //创建Random对象
        Random r = new Random();
        for (int i = 0; i < 26; i++) {
            litter.add((char)('a' + i));
            litter.add((char)('A' + i));
        }
        StringBuilder sb = new StringBuilder();
        //生成数字生成的位置
        int numIndex = r.nextInt(5);
        for (int i = 0; i < 5; i++) {
            //生成随机字母的索引
            int litterIndex = r.nextInt(52);
            if (i == numIndex) {
                sb.append(r.nextInt(9));
            }else {
                sb.append(litter.get(litterIndex));
            }
        }
        return sb.toString();
    }
}
